package com.southminority.ethnic.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 语言类型枚举
 * 
 * @author SouthMinority
 */
@Getter
public enum LanguageTypeEnum {

    /**
     * 汉语
     */
    CHINESE(1, "汉语", "zh"),

    /**
     * 苗语
     */
    MIAO(2, "苗语", "hmn"),

    /**
     * 侗语
     */
    DONG(3, "侗语", "kmc"),

    /**
     * 布依语
     */
    BOUYEI(4, "布依语", "pcc"),

    /**
     * 水语
     */
    SHUI(5, "水语", "swi"),

    /**
     * 彝语
     */
    YI(6, "彝语", "iii"),

    /**
     * 仡佬语
     */
    GELAO(7, "仡佬语", "gio"),

    /**
     * 土家语
     */
    TUJIA(8, "土家语", "tji"),

    /**
     * 回族语
     */
    HUI(9, "回族语", "uig"),

    /**
     * 满语
     */
    MANCHU(10, "满语", "mnc"),

    /**
     * 蒙古语
     */
    MONGOLIAN(11, "蒙古语", "mon"),

    /**
     * 白语
     */
    BAI(12, "白语", "bca"),

    /**
     * 壮语
     */
    ZHUANG(13, "壮语", "za"),

    /**
     * 瑶语
     */
    YAO(14, "瑶语", "ium"),

    /**
     * 毛南语
     */
    MAONAN(15, "毛南语", "mmd"),

    /**
     * 仫佬语
     */
    MULAO(16, "仫佬语", "mlm"),

    /**
     * 京语
     */
    JING(17, "京语", "vie"),

    /**
     * 英语
     */
    ENGLISH(18, "英语", "en");

    /**
     * 语言码
     */
    private final Integer code;

    /**
     * 语言名称
     */
    private final String name;

    /**
     * 语言标识
     */
    private final String locale;

    /**
     * 构造器
     */
    LanguageTypeEnum(Integer code, String name, String locale) {
        this.code = code;
        this.name = name;
        this.locale = locale;
    }

    /**
     * 根据语言码获取枚举
     */
    public static LanguageTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (LanguageTypeEnum language : values()) {
            if (language.getCode().equals(code)) {
                return language;
            }
        }
        return null;
    }

    /**
     * 根据语言标识获取枚举
     */
    public static LanguageTypeEnum getByLocale(String locale) {
        if (locale == null || locale.trim().isEmpty()) {
            return null;
        }
        for (LanguageTypeEnum language : values()) {
            if (language.getLocale().equalsIgnoreCase(locale.trim())) {
                return language;
            }
        }
        return null;
    }

    /**
     * 判断是否为汉语
     */
    public static boolean isChinese(Integer code) {
        return CHINESE.getCode().equals(code);
    }

    /**
     * 判断是否为英语
     */
    public static boolean isEnglish(Integer code) {
        return ENGLISH.getCode().equals(code);
    }

    /**
     * 判断是否为少数民族语言
     */
    public static boolean isMinorityLanguage(Integer code) {
        return code != null && !isChinese(code) && !isEnglish(code) && getByCode(code) != null;
    }
}
